package cloud.daodao.storm.user.controller;

import cloud.daodao.storm.common.model.No;
import cloud.daodao.storm.common.model.Ok;
import cloud.daodao.storm.common.model.Request;
import cloud.daodao.storm.common.model.Response;
import cloud.daodao.storm.common.user.api.OAuth2Api;
import cloud.daodao.storm.common.user.model.oauth2.IdLogin;
import cloud.daodao.storm.common.user.model.oauth2.Login;
import cloud.daodao.storm.common.user.model.oauth2.OAuth2;
import cloud.daodao.storm.user.service.OAuth2Service;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DaoDao
 */
@RestController
public class OAuth2Controller implements OAuth2Api {

    @Resource
    private OAuth2Service oAuth2Service;

    @Override
    public Response<OAuth2> login(Request<Login> request) {
        OAuth2 data = oAuth2Service.login(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<OAuth2> idLogin(Request<IdLogin> request) {
        OAuth2 data = oAuth2Service.idLogin(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<Ok> logout(String authorization, Request<No> request) {
        oAuth2Service.logout(authorization);
        return Response.ok();
    }

}
